package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Date;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.validator.ValidatorUtils;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.FyTeacherEntity;
import io.renren.modules.sys.service.FyTeacherService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-03-04 17:55:30
 */
@RestController
@RequestMapping("sys/fyteacher")
public class FyTeacherController {
    @Autowired
    private FyTeacherService fyTeacherService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:fyteacher:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fyTeacherService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:fyteacher:info")
    public R info(@PathVariable("id") Integer id){
        FyTeacherEntity fyTeacher = fyTeacherService.getById(id);

        return R.ok().put("fyTeacher", fyTeacher);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:fyteacher:save")
    public R save(@RequestBody FyTeacherEntity fyTeacher){
        long time = new Date().getTime()/1000;
        fyTeacher.setCreateTime(Integer.parseInt(String.valueOf(time)));
        fyTeacherService.save(fyTeacher);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:fyteacher:update")
    public R update(@RequestBody FyTeacherEntity fyTeacher){
        ValidatorUtils.validateEntity(fyTeacher);
        fyTeacherService.updateById(fyTeacher);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:fyteacher:delete")
    public R delete(@RequestBody Integer[] ids){
        fyTeacherService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询所有教师信息
     */
    @RequestMapping("/alllist")
    @RequiresPermissions("sys:fyteacher:alllist")
    public R alllist(){
        List<FyTeacherEntity> alllist = fyTeacherService.list(new QueryWrapper<FyTeacherEntity>());
        return R.ok().put("alllist", alllist);
    }
}
